import java.applet.*; import java.awt.*; import java.awt.event.*; class MyFrame extends Frame implements ActionListener { Label lbl,lbl2; TextField txt; Checkbox c1,c2,c3; Button btn; public MyFrame() { setLayout(new FlowLayout()); lbl=new Label("Basic Salary"); Checkbox("Add Bonus Rs 3000"); add(c1); c2=new Checkb add(lbl); txt=new TextField(10); add(txt); c1=new ox("Add HRA rs 2000"); add(c2); c3=new Checkbox("Deduct ITax Rs 2500"); add(c3); btn=new Button("Net Salary"); add(btn); btn.addActionListener(this); lbl2=new Label(); add(lbl2); } public void actionPerformed(ActionEvent e) { String num=txt.getText(); int bs=Integer.parseInt(num); if(c1.getState()) bs=bs+3000; if(c2.getState()) bs=bs+2000; if(c3.getState()) bs=bs-2500; lbl2.setText("Net Salary is Rs "+bs); } } class demo { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setVisible(true); frm.setSize(400,300); } }
import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class MyApplet extends Applet implements ItemListener { Checkbox c1,c2,c3; CheckboxGroup cbg; public void init() { cbg=new CheckboxGroup(); c1=new Checkbox("Red",false,cbg); add(c1); c2=new Checkbox("Green",false,cbg); add(c2); c3=new Checkbox("Blue",false,cbg); add(c3); c1.addItemListener(this); c2.addItemListener(this); c3.addItemListener(this); } public void itemStateChanged(ItemEvent e) { repaint(); } public void paint(Graphics g) { if(c1.getState()) g.setColor(Color.red); if(c2.getState()) g.setColor(Color.green); if(c3.getState()) g.setColor(Color.blue); g.fillOval(50,50,100,100); } } //